//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
package org.jpgolay.me.order;

import java.beans.PropertyVetoException;
import java.math.BigDecimal;
import javax.swing.*;

// Referenced classes of package org.jpgolay.me.order:
//            ShippingOrderGUI
public class ShippingOrderController {

    public ShippingOrderController(JDesktopPane desktop) {
        this.desktop = desktop;
        initComponent();
    }

    private void initComponent() {
        if (shGui == null) {
            shGui = new ShippingOrderGUI();
            shGui.setLocation(280, 540);
        }
        init();
    }

    public void actionOK() {
        try {
            sum = new BigDecimal(shGui.getSumValue());
        } catch (NumberFormatException e) {
            sum = new BigDecimal("0.00");
        }
        actionCANCEL();
    }

    public void actionCANCEL() {
        shGui.setVisible(false);
        desktop.remove(shGui);
    }

    public void init() {
        shGui.setVisible(true);
        shGui.toFront();
        desktop.add(shGui, JLayeredPane.DEFAULT_LAYER);
        try {
            shGui.setSelected(true);
        } catch (PropertyVetoException e) {
            e.printStackTrace();
        }
    }

    public JButton getOK() {
        return shGui.getOKButton();
    }

    public JButton getCANCEL() {
        return shGui.getCANCELButton();
    }

    public BigDecimal getSum() {
        return sum;
    }

    public void setSum(BigDecimal sum) {
        this.sum = sum;
    }
    private JDesktopPane desktop;
    private ShippingOrderGUI shGui;
    private BigDecimal sum;
}
